package com.huatai.bi.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.websocket.Session;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: ganghua
 * @description: 集群消息广播
 * @author: songxiude
 * @create: 2024-09-19 10:06
 **/
@Service
public class WebSocketService {
	@Autowired
	private FanoutSender fanoutSender;

	public  void send(String id, MessageResult message) {
		Map<String, MessageResult> map=new HashMap<>();
		map.put(id,message);
		fanoutSender.sendMessage(map);
	}

	public void sendAll(Map<String, Session> electricSocketMap, MessageResult message) {
		Map<String,MessageResult> map=new HashMap<>();
		for (Map.Entry<String, Session> sessionEntry : electricSocketMap.entrySet()) {
			map.put(sessionEntry.getKey(),message);
		}
		fanoutSender.sendMessage(map);
	}
	public void sendAlls(MessageResult message) {
		fanoutSender.sendMessages(message);
	}
}
